<%--
  Created by IntelliJ IDEA.
  User: B饭老司机
  Date: 2024/3/23
  Time: 16:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="java.sql.*" %>
<%@ page import="util.DBUtil" %>
<%@ page import="entity.PersonBean" %>
<%@ page import="java.util.List" %>
<%@ page import="dao.PersonDAO" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collections" %>
<%@ page import="entity.PageBean" %>
<html>

<head>
    <meta charset="utf-8">

    <title>Bootstrap 布局实例</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/list.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/selectMultip.js"></script>

</head>

<body>

<div class="container-fluid">
    <div class="row">

        <div class="col-sm-12" id="right">
            <ol class="breadcrumb">
                <li class="active">菜单
                </li>
                <li class="active">用户信息
                </li>
            </ol>
            <%
                request.setCharacterEncoding("UTF-8");
                String name = "";
                String worknumber = "";
                String department = "";
                String worktime = "";
                String profession = "";
                if (request.getParameter("name") != null) name = request.getParameter("name");
                if (request.getParameter("worknumber") != null) worknumber = request.getParameter("worknumber");
                if (request.getParameter("department") != null) department = request.getParameter("department");
                if (request.getParameter("worktime") != null) worktime = request.getParameter("worktime");
                if (request.getParameter("profession") != null) profession = request.getParameter("profession");
                ArrayList<String> departmentList=new ArrayList<>();
                if (department.contains(",")) {
                    String[] itemClassesArray = department.split(","); // 使用逗号作为分隔符进行拆分
                    Collections.addAll(departmentList, itemClassesArray); // 将数组中的所有元素添加到列表中
                } else {
                    departmentList.add(department);
                }
                PageBean pageBean = (PageBean) request.getAttribute("pageBean");
            %>
            <div class="panel panel-default">
                <div class="panel-heading">
                    搜索
                </div>
                <div class="panel-body">
                    <form role="form" class="form-inline" action="PersonListServlet" method="post">
                        <div class="form-group">
                            <label for="name">工号</label>
                            <input type="text" class="form-control custom-smaller-input" id="worknumber"
                                   name="worknumber" value="<%=worknumber%>" placeholder="请输入工号">
                        </div>
                        <div class="form-group">
                            <label for="name">姓名</label>
                            <input type="text" class="form-control custom-smaller-input" id="name" name="name"
                                   value="<%=name%>" placeholder="请输入姓名">
                        </div>
                        <div class="form-group">
                            <label for="name">入职时间</label>
                            <input type="date" class="form-control custom-smaller-input" id="worktime" name="worktime"
                                   value="<%=worktime%>">
                        </div>
                        <div class="form-group">
                            <label for="name">部门</label>
                            <select class="form-control" id="department" name="department" multip>
                                <option value="">请选择部门</option>
                                <option value="表面处理车间" <%=departmentList.contains("表面处理车间")?"choose":""%> >表面处理车间</option>
                                <option value="锻压车间" <%=departmentList.contains("锻压车间")?"choose":""%> >锻压车间</option>
                                <option value="组装车间" <%=departmentList.contains("组装车间")?"choose":""%> >组装车间</option>
                                <option value="质检车间" <%=departmentList.contains("质检车间")?"choose":""%> >质检车间</option>
                                <option value="机加车间" <%=departmentList.contains("机加车间")?"choose":""%> >机加车间</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="name">专业</label>
                            <input type="text" class="form-control custom-smaller-input" id="profession"
                                   name="profession" value="<%=profession%>" placeholder="请输入专业">
                        </div>
                        <div class="form-group">
                            <button type="submit" class="searchButton btn btn-primary">搜索</button>
                        </div>
                        <div class="form-group">
                            <a class="addButton btn btn-default" href="PersonEditServlet">添加</a>
                        </div>
                    </form>
                </div>
            </div>
            <!--
            列表展示
        -->
            <div class="table-responsive">
                <table class="table table-striped ">
                    <thead>
                    <tr>
                        <%--<th>序号</th>--%>
                        <th>工作编号</th>
                        <th>姓名</th>
                        <th>电话号码</th>
                        <th>部门</th>
                        <th>入职时间</th>
                        <th>学历</th>
                        <th>专业</th>
                        <th>职称</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <%
                        List<PersonBean> taskList =(List<PersonBean>) request.getAttribute("taskList");
                        if(taskList!=null){
                            for (PersonBean obj : taskList) {
                    %>
                    <tr>
                        <td><%=obj.getWorknumber()%>
                        </td>
                        <td><%=obj.getName()%>
                        </td>
                        <td><%=obj.getPhonenumber()%>
                        </td>
                        <td><%=obj.getDepartment()%>
                        </td>
                        <td><%=obj.getWorktime()%>
                        </td>
                        <td><%=obj.getDegree()%>
                        </td>
                        <td><%=obj.getProfession()%>
                        </td>
                        <td><%=obj.getTitle()%>
                        </td>
                        <td>
                            <div class="btn-group">
                                <a class="reviseButton btn btn-default" href="PersonEditServlet?id=<%=obj.getId()%>" >修改</a>
                                <a class="deleteButton btn btn-danger" href="#" onclick="confirmDelete(<%=obj.getId()%>)">删除</a>
                            </div>
                        </td>
                    </tr>
                    <%
                            }
                        }
                    %>

                    </tbody>
                </table>
            </div>

            <ul class="pagination" style="float: right;">
                <li><span style="pointer-events: none">共<%=pageBean.getPageCount()%>页</span></li>
                <li>
                    <a href="PersonListServlet?alterpage=-1&page=<%=pageBean.getCurPage()%>&name=<%=name%>&worknumber=<%=worknumber%>&department=<%=department%>&worktime=<%=worktime%>&profession=<%=profession%>">&laquo;</a>
                </li>
                <%
                    for (int i = pageBean.getStartPage(); i <= pageBean.getEndPage(); i++) {
                        if (i == pageBean.getCurPage()) {
                            out.println("<li class=\"active\"><a href=\"PersonListServlet?page=" + i + "&name=" + name + "&worknumber=" + worknumber + "&department=" + department + "&worktime=" + worktime + "&profession=" + profession + "\">" + i + "</a></li>");
                        } else {
                            out.println("<li><a href=\"PersonListServlet?page=" + i + "&name=" + name + "&worknumber=" + worknumber + "&department=" + department + "&worktime=" + worktime + "&profession=" + profession + "\">" + i + "</a></li>");
                        }
                    }
                %>
                <li>
                    <a href="PersonListServlet?alterpage=1&page=<%=pageBean.getCurPage()%>&name=<%=name%>&worknumber=<%=worknumber%>&department=<%=department%>&worktime=<%=worktime%>&profession=<%=profession%>">&raquo;</a>
                </li>
            </ul>
        </div>
    </div>
</div>
<!-- 底部页脚部分 -->
<%--<div class="footer">--%>
<%--    <p class="text-center">--%>
<%--        2024 &copy;--%>
<%--    </p>--%>
<%--</div>--%>
<script>
    selectMultip.register()
    function confirmDelete(id) {
        if (confirm("确定要删除吗？")) {
            window.location.href = "PersonDeleteServlet?id=" + id + "&page=<%=pageBean.getCurPage()%>&name=<%=name%>&worknumber=<%=worknumber%>&department=<%=department%>&worktime=<%=worktime%>&profession=<%=profession%>";
        }
    }
    $(function () {
        $('select').selectpicker();
    });
</script>

</body>

</html>